export default class BaseDao {
    private Entity: any;
    public constructor(Entity: any) {
        this.Entity = Entity;
    }
    public async findAll(): Promise<Array<any>> {
        return await this.Entity.findAll()
    }
    public async findById(id: number): Promise<any> {
        return await this.Entity.findByPk(id)
    }
    public async updateById(entity: any): Promise<number> {
        const [affectRowCount] = await this.Entity.update(
            entity.toJSON(),
            {
                where: {
                    id: entity.id
                }
            }
        );
        return affectRowCount;
    }
    public async insert(entity: any): Promise<any> {
        const newRecord = await entity.save()
        return newRecord;
    }
    public async deleteById(id: number): Promise<any> {
        const record = await this.Entity.findByPk(id)
        return await record.destroy();
    }
}